/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.aileron.jww.admin.model.logic;

import java.util.HashMap;
import java.util.List;

import cc.aileron.jww.admin.model.dao.MenuItemDao;
import cc.aileron.jww.admin.model.dto.MenuItem;

import com.google.inject.Inject;

/**
 * @author Aileron
 *
 */
public class MenuItemLogicImpl implements MenuItemLogic
{

    /* (非 Javadoc)
     * @see cc.aileron.jww.admin.model.logic.MenuItemLogic#getAll()
     */
    @Override
    public List<MenuItem> getAll()
    {
        return list;
    }

    /* (非 Javadoc)
     * @see cc.aileron.jww.admin.model.logic.MenuItemLogic#getItem(int)
     */
    @Override
    public MenuItem getItem(int id)
    {
        return map.get(id);
    }

    /**
     * constractor injection
     * @param dao
     */
    @Inject
    public MenuItemLogicImpl(
            final MenuItemDao dao)
    {
        this.list = dao.findByAll();
        for(final MenuItem item : list)
        {
            map.put(item.id, item);
        }
    }
    
    /**
     * list
     */
    private final List<MenuItem> list ;
    
    /**
     * dao
     */
    private final HashMap<Integer,MenuItem> map = new HashMap<Integer, MenuItem>();
}
